package com.ojoin.trade.common.web.quartz;
import org.quartz.spi.TriggerFiredBundle;  
import org.springframework.beans.BeansException;  
import org.springframework.context.ApplicationContext;  
import org.springframework.context.ApplicationContextAware;  
import org.springframework.scheduling.quartz.SpringBeanJobFactory;  
  
public class JobBeanJobFactory extends SpringBeanJobFactory implements ApplicationContextAware {  
      
    private ApplicationContext applicationContext;  
  
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {  
        this.applicationContext = applicationContext;  
    }  
  
    @Override  
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {  
        Object jobInstance = super.createJobInstance(bundle);  
        //把Job交给Spring来管理，这样Job就能使用由Spring产生的Bean了  
        applicationContext.getAutowireCapableBeanFactory().autowireBean(jobInstance);  
        return jobInstance;  
    }  
  
  
}  